<?php
defined('_JEXEC') or die('Restricted access');
$app = JFactory::getApplication();
$input = $app->input;
$action = $input->get('action');

$itemid = $input->get('Itemid');
$items = $this->get('Items');
$this->pagination = $this->get('pagination');
?>

<?php if ($action == 'create'): ?>
<div class="res-title-rg">
    <span class="fl pos-icon text-c"><b class="glyphicon glyphicon-plus fontsize20"></b></span>
    <div class="title-info">
        <h2 class="fontsize20">Create an application</h2>
        <p><a href="#">Home</a>&nbsp;/&nbsp;Setup&nbsp;/&nbsp;Create an application</p>
    </div>
</div>
<div class="ws-content pdall15">
	<div style="width:600px;margin:auto">
		<div style="padding:32px 0 4px 0;text-align:right;font-size:18px;border-bottom:solid 2px #000">Application Form</div>
		<div style="height:32px"></div>
	    <form method="post" class="form-horizontal J_ajaxFsorm" action="/index.php?option=com_console&Itemid=127&task=Applications&action=store">
	        <div class="form-group">
	            <label for="name" class="col-sm-2 control-label">Name</label>
	            <div class="col-sm-10">
	            	<input type="text" class="form-control" id="name" name="name" placeholder="Application name">
	            </div>
	        </div>
			<div class="form-group">
				<label for="name" class="col-sm-2 control-label">Package Name</label>
				<div class="col-sm-10">
					<input type="text" class="form-control" id="name" name="package_name" placeholder="Package Name">
				</div>
			</div>
	        <div class="form-group">
	        	<div class="col-sm-offset-2 col-sm-10">
	        		<button type="submit" class="btn btn-default J_ajax_submit_btn">Create</button>
	        	</div>
	        </div>
	    </form>
	</div>
</div>
<?php elseif ($action == 'edit'): //表单?>
<?php
$model = $this->getModel();
$Item = $model->getItem( (int) $input->get('id'));
?>
<div class="ws-content pdall15">
	<div style="width:600px;margin:auto">
		<div style="padding:32px 0 4px 0;text-align:right;font-size:18px;border-bottom:solid 2px #000">Application Form</div>
		<div style="height:32px"></div>
    	<form method="post" class="form-horizontal J_ajaxFsorm" action="/index.php?option=com_console&Itemid=127&task=Applications&action=update">
        	<input type="hidden" name="id" value="<?php echo $Item->id;?>">
        	<div class="form-group">
            	<label for="name" class="col-sm-3 control-label">Name</label>
            	<div class="col-sm-9">
            		<input type="text" class="form-control" id="name" name="name" value="<?php echo $Item->name;?>" placeholder="Application name">
            	</div>
        	</div>
			<div class="form-group">
				<label for="name" class="col-sm-3 control-label">Package Name</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" id="name" name="package_name" value="<?php echo $Item->package_name;?>"  placeholder="Package Name">
				</div>
			</div>
        	<div class="form-group">
	        	<div class="col-sm-offset-2 col-sm-10">
        			<button type="submit" class="btn btn-default J_ajax_submit_btn">Update</button>
        		</div>
        	</div>
    	</form>
    </div>
</div>

<?php else: ?>
<div class="res-title-rg">
    <span class="fl pos-icon text-c"><i class="setup"></i></span>
    <div class="title-info">
        <h2 class="fontsize20">Applications</h2>
        <p><a href="#">Home</a>&nbsp;/&nbsp;Setup&nbsp;/&nbsp;Applications</p>
    </div>
</div>
<div class="ws-content pdall15">
	<div class="camtab"><a href="/index.php?option=com_console&view=Applications&Itemid=127&task=Applications&action=create" class="fr btn-popup fontsize16">+&nbsp;Create an application</a></div>
	<form action="<?php echo htmlspecialchars(JUri::getInstance()->toString()); ?>" method="post" name="adminForm" id="adminForm">
		<div style="padding:8px">
		 	<table class="table table-hover">
		        <thead>
		        	<tr>
		            	<th>Name</th>
						<th>Package Name</th>
						<th>Key</th>
		            	<th>Operate</th> 
		            </tr>
		        </thead>
		        <tbody>
		        <?php foreach ($items as $key => $item): ?>
		        	<tr>
		            	<td><?php echo $item->name ?></td>
		            	<td><?php echo $item->package_name ?></td>
						<td><?php echo $item->appkey ?></td>
		           		<td>
		           			<a href="/index.php?option=com_console&view=Applications&Itemid=127&task=Applications&action=edit&id=<?php echo $item->id?>">Edit</a>&nbsp;
		           			<a class="layer_confirm" title="are you sure?" href="/index.php?option=com_console&Itemid=127&task=Applications&action=delete&id=<?php echo $item->id?>">Delete</a>
		           		</td> 
		           	</tr>
		        <?php endforeach ?>
		        </tbody>
		    </table>
			<?php // Add pagination links ?>
			<div class="pagination">
				<?php echo $this->pagination->getPagesLinks(); ?>
			</div>
		</div>
	</form>
</div>

<?php endif;?>
